﻿using AJWPFAdmin.Core.Components.AJTable.ViewModels;
using AJWPFAdmin.Core.Enums;
using log4net.Core;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AJWPFAdmin.Core.Models
{
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public class DynamicFormItemDefineAttribute : Attribute
    {
        public interface IOptionsHandle
        {
            List<AJTableFormSchemaItemOptions> CreateOptions();
        }

        public string Label { get; set; }
        public VbenAdminFormType FormType { get; set; }
        public bool Disable { get; set; }

        public Type OptionsHandler { get; set; }

        public DynamicFormItemDefineAttribute(string label, 
            VbenAdminFormType formType  = VbenAdminFormType.Input, Type optionsHandler = null)
        {
            Label = label;
            FormType = formType;
            OptionsHandler = optionsHandler;
        }
    }

    public class DynamicFormItemSchema : BindableBase
    {
        private string _label;
        public string Label
        {
            get { return _label; }
            set { SetProperty(ref _label, value); }
        }

        private string _field;
        public string Field
        {
            get { return _field; }
            set { SetProperty(ref _field, value); }
        }

        private object _value;
        public object Value
        {
            get { return _value; }
            set { SetProperty(ref _value, value); }
        }

        private ObservableCollection<AJTableFormSchemaItemOptions> _options;
        public ObservableCollection<AJTableFormSchemaItemOptions> Options
        {
            get { return _options; }
            set { SetProperty(ref _options, value); }
        }

        private AJTableFormSchemaItemOptions _selectedOption;
        public AJTableFormSchemaItemOptions SelectedOption
        {
            get { return _selectedOption; }
            set 
            { 
                if(SetProperty(ref _selectedOption, value))
                {
                    Value = value?.Value;
                }
            }
        }

        private VbenAdminFormType _formType;
        public VbenAdminFormType FormType
        {
            get { return _formType; }
            set { SetProperty(ref _formType, value); }
        }

        private bool _disable;
        public bool Disable
        {
            get { return _disable; }
            set { SetProperty(ref _disable, value); }
        }
    }
}
